# windows编译.so文件
CC = gcc
# CC = x86_64-w64-mingw32-gcc 32位兼容使用D:\cygwin64\bin包下另一个gcc
# CC = x86_64-pc-cygwin-gcc
ROOTPATH = ../..
SPIFLASHLIBRARIE32F4 = ./libraries/CMSIS/Device/ST/STM32F4xx
SPIFLASHLIBRARIESource = ./libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates
SPIFLASHLIBRARIEInclude = ./libraries/CMSIS/Include
INCLUDECMSISOS = ./libraries/CMSIS/RTOS/Template
STM32HALDRIVER = ./libraries/STM32F4xx_HAL_Driver
PORTFAL = ../../port/fal
INCLUDE = -I./applications -I./drivers -I$(ROOTPATH)/inc -I$(PORTFAL)/inc -I./sfud/inc -I$(SPIFLASHLIBRARIE32F4)/Include -I$(SPIFLASHLIBRARIEInclude) -I$(INCLUDECMSISOS) -I$(STM32HALDRIVER)/Inc -I$(STM32HALDRIVER)/Inc/Legacy
# Windows 上不需要 -lpthread
LIB = 
# 使用 out 目录存放所有的对象文件
OBJ_DIR = out

OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard sfud/port/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard sfud/src/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(STM32HALDRIVER)/Src/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(STM32HALDRIVER)/Src/Legacy/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(SPIFLASHLIBRARIESource)/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard drivers/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard applications/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(ROOTPATH)/src/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(ROOTPATH)/samples/*.c))

CFLAGS = -O0 -g3 -Wall -fPIC
LDFLAGS = -shared
target = libflashdb.dll
all: $(target)

$(target): $(OBJ)
	$(CC) $(LDFLAGS) $(OBJ) -o $(target) $(LIB)
	mkdir -p $(OBJ_DIR)
	mv $(target) $(OBJ_DIR)

$(OBJ_DIR)/%.o: %.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE)

clean:
	rm -rf $(OBJ_DIR)/*



